package zb.WX.service.menu;

import com.google.gson.Gson;
import zb.WX.bean.menu.Menu;
import zb.WX.bean.menu.MenuFather;
import zb.WX.bean.menu.MenuMatchrule;
import zb.WX.util.AccessTokenSaveUtil;
import zb.WX.util.GlobalVar;
import zb.WX.util.HttpsUtil;

import java.util.ArrayList;
import java.util.List;


/**
 * 创建个性化菜单
 *
 * @author Administrator
 */
public class Special {
    public String specila() {
        String access_token = AccessTokenSaveUtil.getLocationAccesstonken();
        String urlStr = GlobalVar.SPECIALMENU.replace("ACCESS_TOKEN", access_token);
        String result = HttpsUtil.getHttpsToJson(urlStr, new Special().createSpecila1());
        return result;
    }

    /*
     * 个性化菜单1
     * 按性别匹配
     */
    public String createSpecila1() {
        //设置1个一级菜单做演示
        MenuFather mf1 = new MenuFather();
        mf1.setName("登 录");
        mf1.setType("view");
        mf1.setUrl(zb.blog.base.global.GlobalVar.WEB_SITE + "/login.html");
        mf1.setKey("3");

        //设置匹配规则
        MenuMatchrule matchrule = new MenuMatchrule();
        matchrule.setGroup_id("101");

        //将按钮和匹配规则设置到菜单中
        Menu menu = new Menu();
        List<MenuFather> list = new ArrayList<MenuFather>();
        list.add(mf1);
        menu.setList(list);
        //menu.setMenuMatchrule(matchrule);

        //将对象格式转化为json格式返回
        Gson gson = new Gson();
        String menuJson = gson.toJson(menu);
        System.out.println("个性化菜单1" + menuJson);
        return menuJson;
    }

    /*
     * 个性化菜单3
     * 按分组匹配
     */
    public String createSpecila3() {
        return null;
    }


    public static void main(String[] args) {
        new Special().specila();
    }
}
